//
//  LMOpaqueBtn.m
//  MeetCard
//
//  Created by longmin on 16/12/2.
//  Copyright © 2016年 timtian. All rights reserved.
//

#import "LMOpaqueBtn.h"

@implementation LMOpaqueBtn

#pragma mark - 生命周期
#pragma mark - Event

-(void)btnClick:(LMOpaqueBtn *)btn {
    if (self.onClick) {
        self.onClick(btn);
    }
}

#pragma mark - Public

+ (instancetype)opaqueBtnWithImage:(NSString *)image title:(NSString *)title font:(UIFont *)font space:(CGFloat)space {
    
    LMOpaqueBtn *opaqueBtn = [[LMOpaqueBtn alloc] init];
    [opaqueBtn addTarget:opaqueBtn action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    opaqueBtn.titleLabel.font = font ? font : _kFontSub;
    
    UIImage *btnImg = [UIImage imageNamed:image];
    CGSize imgSize = btnImg.size;
    
    opaqueBtn.space = space;
    UILabel *sizeLabel = [[UILabel alloc] init];
    sizeLabel.text = title;
    sizeLabel.font = opaqueBtn.titleLabel.font;
    [sizeLabel sizeToFit];
    CGSize titleSize = sizeLabel.size;
    
    
    [opaqueBtn setImage:btnImg forState:UIControlStateNormal];
    [opaqueBtn setTitle:title forState:UIControlStateNormal];
    [opaqueBtn setTitleColor:kColorA6A6A6 forState:UIControlStateNormal];
    opaqueBtn.width = imgSize.width + space + titleSize.width;
    NSLog(@"%f",opaqueBtn.width);
    opaqueBtn.height = 40;
    
    [opaqueBtn setNeedsLayout];
    
    return opaqueBtn;
}

#pragma mark - Private
#pragma mark - 数据源和代理方法
#pragma mark - UIView -> 下面放继承自UIView的方法

-(void)layoutSubviews {
    [super layoutSubviews];
    
    self.imageView.left = 0;
    self.imageView.centerY = self.height * 0.5;
    
    [self.titleLabel sizeToFit];
    self.titleLabel.left = self.imageView.right + self.space;
    self.titleLabel.centerY = self.imageView.centerY;
    
}

#pragma mark - set方法和get方法


@end
